//*****************************************************************************
// file        : ad2428.h
// ad2428 device driver.
// Copyright (c) 2012-2024 Dynaudio Technology co. Ltd. All rights reserved
//
// Change Logs:
// Date                 Author      Note
// 2024/03/01           Cheney      First draft version
// 2024/03/05           Cheney      1. Add peripheral access api.
//                                  2. Add remote a2b slave note pin access api.
// 2024/04/26           Cheney      Add ad2428 setup async api.
//
//*****************************************************************************
#ifndef __AD2428_H__
#define __AD2428_H__

//*****************************************************************************
//
//! \addtogroup ad2428
//! @{
//
//*****************************************************************************
#include "stdint.h"
#include "stdbool.h"
#include "a2b_cfg.h"

//*****************************************************************************
//
// If building with a C++ compiler, make all of the definitions in this header
// have a C binding.
//
//*****************************************************************************
#ifdef __cplusplus
extern "C"
{
#endif

/**
 * @brief ad2428 main function call period
 *
 */
#define AD2428_MAIN_FUNCTION_PERIOD             10

//*****************************************************************************
//
// Prototypes for the APIs.
//
//*****************************************************************************
int ad2428_init(void);
int ad2428_deinit(void);

/* local register access api. */
int ad2428_read_local_reg(A2bNetworkInfo_t *info, uint8_t nRegAddr, uint8_t *regVal);
int ad2428_write_local_reg(A2bNetworkInfo_t *info, uint8_t nRegAddr, uint8_t regVal);

/* remote register access api. */
int ad2428_read_remote_reg(A2bNetworkInfo_t *info, uint8_t nNodeAddr, uint8_t nRegAddr,
                           uint8_t nRead, uint8_t *rbuf);
int ad2428_write_remote_reg(A2bNetworkInfo_t *info, uint8_t nNodeAddr, uint8_t nRegAddr,
                            uint8_t nWrite, uint8_t *wbuf);

/* remote peripheral access api. */
int ad2428_read_remote_peri_reg(A2bNetworkInfo_t *info, uint8_t nNodeAddr, uint8_t ChipAddr,
                                uint8_t nRegAddr, uint8_t nRead, uint8_t *rbuf);
int ad2428_write_remote_peri_reg(A2bNetworkInfo_t *info, uint8_t nNodeAddr, uint8_t ChipAddr,
                                 uint8_t nRegAddr, uint8_t nWrite, uint8_t *wbuf);

/* remote port and pin access api. */
int ad2428_set_remote_port_direction(A2bNetworkInfo_t *info, uint8_t nNodeAddr, uint8_t dir);
int ad2428_write_remote_port(A2bNetworkInfo_t *info, uint8_t nNodeAddr, uint8_t val);
int ad2428_read_remote_port(A2bNetworkInfo_t *info, uint8_t nNodeAddr, uint8_t *val);
int ad2428_set_remote_pin(A2bNetworkInfo_t *info, uint8_t nNodeAddr, uint8_t pin, uint8_t val);
int ad2428_get_remote_pin(A2bNetworkInfo_t *info, uint8_t nNodeAddr, uint8_t pin, uint8_t *val);

/* network setup api. */
int ad2428_network_setup_sync(A2bNetworkInfo_t *info, Ad2428ConfigList_t *config, uint32_t config_length);
int ad2428_network_setup_async(A2bNetworkInfo_t *info, Ad2428ConfigList_t *config, uint32_t config_length);
void ad2428_network_setup_mainfunction(void);

//*****************************************************************************
//
// Mark the end of the C bindings section for C++ compilers.
//
//*****************************************************************************

#ifdef __cplusplus
}
#endif

//*****************************************************************************
//
// Close the Doxygen group.
//! @}
//
//*****************************************************************************
#endif //  __AD2428_H__